package com.megurokai.paint;

import android.content.Context;
import android.graphics.Canvas;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

import com.test.android.view.GraphicView;

public class PaintView extends GraphicView {
	protected static PaintManager manager = null;

	// コンストラクタ
	public PaintView(Context context) {
		super(context);
		init();
	}
	public PaintView(Context context, SurfaceView view){
		super(context, view);
		init();
	}
	
	// 初期化
	private void init(){
		if(manager == null){
			manager = PaintManager.getInstance();
		}
	}
	
	// ツールをブラシに変更
	public void setBrush(){
		manager.setBrush();
	}
	
	// ツールを鉛筆に変更
	public void setPencil(){
		manager.setPencil();
	}
	
	// ツールを移動に変更
	public void setScroll(){
		manager.setScroll();
	}
	
	// ツールをズームに変更
	public void setZoom(){
		manager.setZoom();
	}
	
	// Undoを実行
	public void undo(){
		manager.undo();
	}
	
	// Redoを実行
	public void redo(){
		manager.redo();
	}
	
	// 画面を描画する
	@Override
	public void drawCanvas(Canvas canvas){
		manager.draw(canvas);
	}
	
	// SurfaceViewオーバーライドメソッド
	public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
		super.surfaceChanged(holder, format, width, height);
		manager.setView(this);
	}
	// イベントハンドラ
	@Override
	public boolean onTouchUp(MotionEvent event){
		return manager.onTouchUp(event);
	}
	@Override
	public boolean onTouchDown(MotionEvent event){
		return manager.onTouchDown(event);
	}
	@Override
	public boolean onTouchMove(MotionEvent event){
		return manager.onTouchMove(event);
	}
	public boolean onScale(ScaleGestureDetector det) {
		return manager.onScale(det);
	}
	public boolean onScaleBegin(ScaleGestureDetector det) {
		return manager.onScaleBegin(det);
	}
	public void onScaleEnd(ScaleGestureDetector det) {
		manager.onScaleEnd(det);
	}
	public void onOptionMenu(){
		manager.onOptionMenu();
	}
	
	// セッター・ゲッター
	public void setCallback(Callback<Status> callback){
		manager.setCallback(callback);
	}
	
	public void setStrokeWidth(int value){
		manager.setStrokeWidth(value);
	}
	
	public void setAlpha(int value){
		manager.setAlpha(value);
	}
	
	// 画面描画間隔を返す
	@Override
	public long getUpdateInterval(){
		return 10;
	}
	public int getScreenWidth(){
		return screenWidth;
	}
	public int getScreenHeight(){
		return screenHeight;
	}
}
